AMW-590 Collection spelling and grammar checking for PRs - #24
AMW-590 Collection spelling and grammar checking for PRs#24RanabirChakraborty wants to merge 1 commit into
Conversation
|
A couple of notes:
|
|
|
||
|
|
||
| def _load_accepted_terms(): | ||
| """Load accepted spelling terms from the shared Vale vocabulary file.""" |
| SKIP_RULES = { | ||
| "write-good.TooWordy", | ||
| "write-good.Weasel", | ||
| } |
There was a problem hiding this comment.
Couldn't this be part of a shared vale.ini that can be overridden by a project's own vale.ini?
5391576 to
00a2a10
Compare
|
@iweiss Thanks for the suggestions, Fixed it accordingly. |
| current = parent | ||
|
|
||
|
|
||
| VALE_CONFIG = _find_vale_config() |
There was a problem hiding this comment.
Currently it silently returns a nonexistent path. We can add an error msg to handle this and also in the README we have mentioned that in every collection root path we need to have .vale.ini file present.
There was a problem hiding this comment.
Any error should be raised to avoid confusion, as a warning or error depending on the context.
There was a problem hiding this comment.
thanks, the FileNotFoundError was already raised inside the function but was called at module level, so a missing .vale.ini would surface as a raw Python traceback in CI. Using try/except to catch it and print a clean Error msg to stderr before exiting with code.
| with tempfile.NamedTemporaryFile( | ||
| mode='w', suffix='.md', dir=PROJECT_ROOT, delete=False | ||
| ) as tmp: | ||
| tmp.write(clean + '\n') |
There was a problem hiding this comment.
What is being accomplished by writing this temporary file?
There was a problem hiding this comment.
Actually Vale's CLI only accepts file paths, it has no stdin mode. Adding a comment here.
There was a problem hiding this comment.
You're right, the .md temp file should sit beside the config, not in project root path. _build_tasks_config() already does this correctly for the .ini file. Fixed to derive config_dir from the passed config path and use that as the dir for the .md temp file too.
| FQCN | ||
| Jinja | ||
| jinja | ||
| playbook |
There was a problem hiding this comment.
Isn't this in the standard English dictionary?
| colocated | ||
| multicast | ||
| infinispan | ||
| idempotency |
| utils | ||
| repo | ||
| repos | ||
| boolean |
| It runs two checks in every pull request: | ||
|
|
||
| 1. **Prose files** — Vale lints all Markdown and RST files in the collection using the styles configured in the project's `.vale.ini`. | ||
| 2. **Ansible YAML name fields** — A Python script extracts `name:` fields from task files, handler files, playbooks, and Molecule scenarios and runs them through Vale individually, suppressing rules that are too noisy for short imperative strings. |
| Spell and grammar checking for ansible-middleware collections using [Vale](https://vale.sh/). | ||
| It runs two checks in every pull request: | ||
|
|
||
| 1. **Prose files** — Vale lints all Markdown and RST files in the collection using the styles configured in the project's `.vale.ini`. |
There was a problem hiding this comment.
I don't see a .vale.ini in this PR. Is this on purpose?
There was a problem hiding this comment.
I think .vale.ini should be independent to the collection, that's why haven't provided any .vale.ini here, we can add one in the collection root path. Also added an example in README.
| name: Spelling and Grammar check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 |
There was a problem hiding this comment.
Always suggest and use the latest version of an action, even in examples.
| @@ -0,0 +1,106 @@ | |||
| Ranabir | |||
There was a problem hiding this comment.
Can't the authors key/array be excluded from checking?
| TokenIgnores = (?:[a-z][a-z\d]*_)+[a-z\d_]+ | ||
| ``` | ||
|
|
||
| `TokenIgnores` is important: it prevents Vale from spell-checking Ansible `snake_case` variable names inside prose. |
There was a problem hiding this comment.
What do you mean by "inside prose" in this context?
There was a problem hiding this comment.
like for this case, jboss_home appears within a sentence in a Markdown or RST file. Vale would split it at underscores and flag jboss and home separately as misspelled words. Inside prose means the underscored vars. Explained in the comment as well.
00a2a10 to
9880727
Compare
| current = parent | ||
|
|
||
|
|
||
| VALE_CONFIG = _find_vale_config() |
There was a problem hiding this comment.
Any error should be raised to avoid confusion, as a warning or error depending on the context.
| with tempfile.NamedTemporaryFile( | ||
| mode='w', suffix='.md', dir=PROJECT_ROOT, delete=False | ||
| ) as tmp: | ||
| tmp.write(clean + '\n') |
| os.unlink(tasks_config) | ||
|
|
||
| if found_issues: | ||
| sys.exit(1) |
| # .github/vale-tasks.ini — project-specific task name rule tuning | ||
| write-good.TooWordy = NO | ||
| write-good.Weasel = NO | ||
| proselint.LGBTTerms = NO |
| # Replace snake_case tokens (e.g. jboss_home) with a placeholder so Vale | ||
| # does not flag each underscore-joined segment as a misspelled word. | ||
| clean = re.sub(r'\b(?:[a-z][a-z\d]*_)+[a-z\d_]+\b', 'VARNAME', clean) | ||
|
|
There was a problem hiding this comment.
What happens if someone writes jbos_home?
There was a problem hiding this comment.
thanks, so I'm thinking if we can do something like this, we can add both the project's merged vocabulary (.github/styles/config/vocabularies/Base/accept.txt) which is already there and also add the support of the shared action vocabulary (.github/vale-lint/vocabularies/accept.txt), Now _load_accepted_terms() should load both vocabularies (shared action + project) so segment lookups are complete.
Replace the blanket snake_case regex substitution with a per-token check: split the token on _, and only replace with VARNAME if every segment is in the combined accepted terms set. Otherwise leave it as-is so Vale sees the bad segment (e.g. jbos from jbos_home). wdyt?
There was a problem hiding this comment.
Doesn't it do this already, #24 (comment)?
There was a problem hiding this comment.
yes, so even if we use jbos_home it detect it and throws an error as flags jbos as a spelling error. I guess this is what we wanted it to do.
| name: Spelling and Grammar check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 |
There was a problem hiding this comment.
v7.0.1 is the latest, https://github.com/actions/checkout/releases
There was a problem hiding this comment.
@v7 is a floating tag that GH keeps pointed at the latest v7.x.x patch (currently v7.0.1), so users always get the latest stable release without manually updating it. Using @v7.0.1 would pin to a specific patch.
9880727 to
cf9e424
Compare
Issue: http://redhat.atlassian.net/browse/AMW-590